﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Web
{
    public class AppendLayoutModel
    {
    }

    public class AppendLayoutModelAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            int memberid = filterContext.HttpContext.User.Identity.Name.ToInt();
            string url = filterContext.HttpContext.Request.Url.AbsolutePath;
            bool ismobile = Adams.Web.Controllers.MobileCheck.IsMobile();

            var model = Adams.Web.Logic.Layout.PageLoad(memberid, url, ismobile);

            filterContext.Controller.ViewBag.Layout = model;
            filterContext.Controller.ViewBag.IsLoggedIn = memberid > 0;
            filterContext.Controller.ViewBag.FirstName = model.FirstName;
            filterContext.Controller.ViewBag.LastName = model.LastName;
            filterContext.Controller.ViewBag.Email = model.Email;
            base.OnActionExecuting(filterContext);
        }
    }
}